<?php

/**
 * Created by PhpStorm.
 * User: yulongyang
 * Date: 2017/3/1
 * Time: 下午3:18
 */

/**
 * 简单测试程序耗时的类
 * Class timer
 */
class timer
{
    private $start;
    private $end;
    
    private function now ()
    {
        echo microtime();
        list($usec, $sec) = explode(' ', microtime());
        return ((float)$usec + (float)$sec);
    }
    
    public function start ()
    {
        echo $this->start = $this->now();
    }
    
    public function end()
    {
        echo $this->end = $this->now();
    }
    
    private function getTime()
    {
        return ($this->end - $this->start);
    }
    
    public function printTime()
    {
        echo $this->start;
        echo "\r\n ------ \r\n";
        echo $this->end;
        printf("Program run use time: %fs \n", $this->getTime());
    }
}

$time = new timer();
$time->start();
for ($i = 0; $i < 10; $i++) {
    usleep(15000);
}
$time->end();
$time->printTime();

